//
//  XqViewController.m
//  豆瓣
//
//  Created by hy on 16/1/5.
//  Copyright © 2016年 hongyu. All rights reserved.
//

#import "XqViewController.h"
#import "HyModel.h"
#import "UIImageView+WebCache.h"
#import "hydateBaseHandle.h"
@interface XqViewController ()

@end

@implementation XqViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = self.dic[@"title"];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"sc.png"] style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
    //    设置颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = item;
    [item release];

    
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(180, 50, 150, 40)];
    label.text = [NSString stringWithFormat:@"影名 : %@", _dic[@"title"]];
    [self.view addSubview:label];
    [label release];
    
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(180, 100, 100, 40)];
    label1.text = [NSString stringWithFormat:@"评分 : %@", _dic[@"rating"]];
    [self.view addSubview:label1];
    [label1 release];
    
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(180, 150, 150, 40)];
    label2.text = [NSString stringWithFormat:@"上映 : %@", _dic[@"pubdate"]];
    [self.view addSubview:label2];
    [label2 release];
    
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(15, 30, 130, 200)];
    [image sd_setImageWithURL:[NSURL URLWithString:_dic[@"images"][@"large"]]];
    [self.view addSubview:image];
    [image release];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(80, 300, 100, 50)];
    title.text = @"观影人数 : ";
    [self.view addSubview:title];
    [title release];
    
    UILabel *gy = [[UILabel alloc] initWithFrame:CGRectMake(170, 300, 250, 50)];
    gy.text = _dic[@"id"];
    gy.font = [UIFont boldSystemFontOfSize:20];
    gy.textColor = [UIColor redColor];
    [self.view addSubview:gy];
    [gy release];
    self.kongArr = [NSMutableArray array];
    
 
   
    
}
- (void)itemAction:(UIBarButtonItem *)item {
    NSArray *arr = [[hydateBaseHandle shareDataBaseHandle] selectMovieDate];
    NSMutableArray *array = [NSMutableArray array];
    for (HyModel *model in arr) {
        NSString *str = model.title;
        [array addObject:str];
    }
    if (![array containsObject:_dic[@"title"]]) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"收藏成功" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:nil];
        [alert addAction:action];
        [self presentViewController:alert animated:YES completion:nil];
        [[hydateBaseHandle shareDataBaseHandle] insertmovie:_dic[@"title"]];
    } else if ([array containsObject:_dic[@"title"]]) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"电影已收藏" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:nil];
        [alert addAction:action];
        [self presentViewController:alert animated:YES completion:nil];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
